package serializable.gson;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import serializable.testdata.DataObject;

public class GsonTest {
	public static void main(String[] args)  {
		DataObject dataObject = new DataObject();
		dataObject.setMyData("1111111111111111111" + "11111111111112222222222222"
				+ "333333333333333");
		GsonBuilder gson = new GsonBuilder();
		gson.setPrettyPrinting().create();
		
		String json = gson.create().toJson(dataObject);
		File file = new File("stotr3.bin");
		
		try(PrintWriter out=new PrintWriter(file.getName());) {
			out.println(json);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		DataObject dataObject2 = gson.create().fromJson(json, DataObject.class);
		System.out.println(dataObject2.getMyData());
	}
}
